<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="课程名称" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入课程名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['scheduling:scheduling:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['scheduling:scheduling:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['scheduling:scheduling:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['scheduling:scheduling:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="schedulingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="机构ID" align="center" prop="deptId" />
      <el-table-column label="课程名称" align="center" prop="className" />
      <el-table-column label="关联课程" align="center" prop="classCourse" />
      <el-table-column label="班级容量" align="center" prop="classCapacity" />
      <el-table-column label="请假默认计课时" align="center" prop="classAskforleave" />
      <el-table-column label="未到默认计课时" align="center" prop="classNoyet" />
      <el-table-column label="周几排课" align="center" prop="classWorkOut" />
      <el-table-column label="循环方式" align="center" prop="classCirculate">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.class_circulate" :value="scope.row.classCirculate"/>
        </template>
      </el-table-column>
      <el-table-column label="上课时间开始" align="center" prop="classStart" />
      <el-table-column label="上课时间结束" align="center" prop="classFinish" />
      <el-table-column label="课时数" align="center" prop="classHours" />
      <el-table-column label="授课教师" align="center" prop="classTeacher" />
      <el-table-column label="考勤员" align="center" prop="classAttendant" />
      <el-table-column label="上课教师" align="center" prop="classRoom" />
 
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['scheduling:scheduling:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['scheduling:scheduling:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改课程表对话框 -->
    <el-dialog :title="title" :visible.sync="open" direction="rtl" size="35%" :show-close="false">

      <el-row :gutter="20">
        <el-col :span="12">
          <div class="ml30">
            <div class="grid-content bg-purple-dark    text-size-23-w700  ">新增排课</div>

            <div class="grid-content bg-purple     text-size-16 mt20 text-gray  ">切换为日历模式可以单独选择日期</div>

          </div>

        </el-col>
        <el-col :span="12">
          <div class="classflex-end">
          <el-button @click="cancel" style="width: 100px;margin-right: 100px;">日历模式</el-button>
            <el-button @click="cancel" style="width: 100px;margin-right: 100px;">取消</el-button>

          </div>

        </el-col>
      </el-row>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
         <el-divider style="width: 80%;"></el-divider>

         <div class="ml20 mr20">
           <el-row :gutter="20">
             <el-col :span="12">
               <el-form-item label="排课班级" prop="className">
                 <el-input v-model="form.className" placeholder="请输入课程" />
               </el-form-item>
             </el-col>
             <el-col :span="12">

                 <el-input v-model="form.orderCourse" placeholder="请输入默认班级" />

             </el-col>

           </el-row>
         </div>
         <div class="ml20">
           <el-form-item label="排课周期" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入排课周期"  style="width: 360px;"/>
            </el-form-item>
            <el-form-item label="周几排课" prop="classWorkOut">
              <el-input v-model="form.classWorkOut" placeholder="请输入周几排课" style="width: 360px;"/>
            </el-form-item>
            <el-form-item label="循环方式" prop="classCirculate">
              <el-select v-model="form.classCirculate" placeholder="请选择循环方式" style="width: 360px;">
                <el-option
                  v-for="dict in dict.type.class_circulate"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="开始时间" prop="classStart">
              <el-input v-model="form.classStart" placeholder="请输入上课时间开始" style="width: 360px;"/>
            </el-form-item>
            <el-form-item label="结束时间" prop="classFinish">
              <el-input v-model="form.classFinish" placeholder="请输入上课时间结束" style="width: 360px;"/>
            </el-form-item>
            <el-form-item label="课时数" prop="classHours">
              <el-input v-model="form.classHours" placeholder="请输入课时数" style="width: 360px;"/>
            </el-form-item>
           <el-form-item label="授课教师" prop="classTeacher">
             <el-input v-model="form.classTeacher" placeholder="请输入上课教室" style="width: 360px;"/>
           </el-form-item>

           <el-form-item label="考勤员" prop="remark3">
             <el-input v-model="form.remark3" placeholder="请输入考勤员" style="width: 360px;"/>
           </el-form-item>
           <el-form-item label="上课教室" prop="classRoom">
             <el-input v-model="form.classRoom" placeholder="请输入上课教室"  style="width: 360px;"/>
           </el-form-item>
         </div>
      </el-form>
      <el-divider></el-divider>
      <div class="ml20 mr20">
        <el-button type="primary" @click="submitForm" style="width: 100%;">立即创建</el-button>
        <!-- <el-button @click="cancel">取 消</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScheduling, getScheduling, delScheduling, addScheduling, updateScheduling } from "@/api/scheduling/scheduling";

export default {
  name: "Scheduling",
  dicts: ['class_circulate'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 课程表表格数据
      schedulingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        className: null,
        classCourse: null,
        classCapacity: null,
        classAskforleave: null,
        classNoyet: null,
        classWorkOut: null,
        classCirculate: null,
        classStart: null,
        classFinish: null,
        classHours: null,
        classTeacher: null,
        classAttendant: null,
        classRoom: null,
        classStudent: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询课程表列表 */
    getList() {
      this.loading = true;
      listScheduling(this.queryParams).then(response => {
        this.schedulingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptId: null,
        className: null,
        classCourse: null,
        classCapacity: null,
        classAskforleave: null,
        classNoyet: null,
        classWorkOut: null,
        classCirculate: null,
        classStart: null,
        classFinish: null,
        classHours: null,
        classTeacher: null,
        classAttendant: null,
        classRoom: null,
        classStudent: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        remark2: null,
        remark3: null,
        remark4: null,
        remark5: null,
        remark6: null,
        remark7: null,
        remark8: null,
        remark9: null,
        remark10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加课程表";
       this.form.deptId=   this.$store.state.user.deptId;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getScheduling(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改课程表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateScheduling(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScheduling(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除课程表编号为"' + ids + '"的数据项？').then(function() {
        return delScheduling(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('scheduling/scheduling/export', {
        ...this.queryParams
      }, `scheduling_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
